//package com.zmn.plat.task.job.channel;
//
//import com.github.ltsopensource.core.domain.Action;
//import com.github.ltsopensource.core.domain.Job;
//import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
//import com.github.ltsopensource.spring.tasktracker.LTS;
//import com.github.ltsopensource.tasktracker.Result;
//import com.zmn.common.dto.ResultDTO;
//import com.zmn.common.utils.date.DateUtil;
//import com.zmn.manager.lts.interfaces.task.TaskManager;
//import com.zmn.plat.manager.utils.TaskConsts;
//import com.zmn.plat.model.entity.channel.ChannelCommission;
//import com.zmn.plat.services.interfaces.channel.ChannelCommissionService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import javax.annotation.PostConstruct;
//import java.util.List;
//
//
///**
// * 渠道佣金比例更新JOB
// *
// * @author xiangjunming
// * @since 2019/09/04 15:28:09
// */
//@LTS
//public class ChannelCommissionJob {
//
//    private Logger logger = LoggerFactory.getLogger(ChannelCommissionJob.class);
//
//    @Autowired
//    private ChannelCommissionService commissionService;
//
//    @Autowired
//    private TaskManager taskManager;
//
//    /**
//     * Init.
//     */
//    @PostConstruct
//    void init() {
//        Job job = new Job();
//        job.setTaskId(TaskConsts.TASK_ID_CHANNEL_COMMISSION_REFRESH);
//        job.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_CHANNEL_COMMISSION_REFRESH);
//        //每5分钟执行一次
//        job.setCronExpression("0 0/5 * * * ?");
//        job.setReplaceOnExist(true);
//        ResultDTO result = taskManager.submitTask(job);
//        if (!result.getStatusBool()) {
//            logger.error("#channel_commission# job submit fail...");
//        }
//    }
//
//    /**
//     * 渠道佣金比例更新
//     *
//     * @param job the job
//     * @return result
//     */
//    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_CHANNEL_COMMISSION_REFRESH)
//    public Result runChannelCommissionJob(Job job) {
//
//        logger.debug("#job#channel_commission#start running...");
//
//        List<ChannelCommission> commissions = commissionService.listByCommissionNewNotNull();
//        Integer count = 0;
//        if (commissions != null && commissions.size() > 0) {
//            for (ChannelCommission commission : commissions) {
//                //新佣金比例生效时间小于系统时间则更新佣金比例
//                commission.setCommissionCurrent(commission.getCommissionNew());
//                commission.setCommissionNew(null);
//                if(commission.getCommissionTypeNew() != null) {
//                    commission.setCommissionType(commission.getCommissionTypeNew());
//                    commission.setCommissionTypeNew(null);
//                }
//                if(commission.getBaseTypeNew() != null) {
//                    commission.setBaseType(commission.getBaseTypeNew());
//                    commission.setBaseTypeNew(null);
//                }
//                commission.setEffectiveTime(null);
//                commission.setUpdateTime(DateUtil.getNow());
//                commission.setUpdater("SYSTEM");
//                commissionService.updateByKey(commission);
//                count++;
//            }
//        }
//
//        logger.debug("#job#channel_commission#end running... update count :" + count);
//        return new Result(Action.EXECUTE_SUCCESS, "渠道佣金比例更新完成! update count:" + count);
//    }
//
//}
